#获取一个对象的所有方法:dir()

'''s1='sffa'
print(dir(s1))
print('__iter__'in dir(s1))#判断对象是否可迭代
print('__iter__'in dir(range(10)))
print('__next__'in dir(s1))
print('__next__'in dir(range(10)))
'''

#生成器
def func():
    print(111)
    print(222)
    yield 3
    a=1
    b=2
    c=a+b
    print(c)
    yield 4
#print(func)#<function func at 0x000001F7F1BEC268>
ret=func()#不执行
'''
print(next(ret))
111   一个next对应一个yield
222
3
'''
print(next(ret))
print(next(ret))

#吃包子
# def func():
#     l1=[]
#     for i in range(1,5001):
#         l1.append(f'{i}号包子')
#     return l1
# ret=func()
# print(ret)

def get_func():
    for i in range(1,5001):
        yield f'{i}号包子'

ret=get_func()
# print(list(ret))
for i in range(200):
    print(next(ret))


#yield from
def func():
    l1=[1,2,3,4,5]
    yield from l1
    #将l1列表变成了迭代器
    '''
    yield 1
    yield 2
    yield 3
    yield 4
    yield 5
    '''

ret=func()
print(next(ret))#返回每一个元素
print(next(ret))
print(next(ret))
print(next(ret))
print(next(ret))
print('*'*20)

def func():
    list1=[1,2,3,4]
    list2=[6,7,8,9]
    yield from list1
    yield from list2
g=func()
for i in range(8):
    print(next(g))
